package DD9;

public class Dog implements Comparable<Object> {
	int age;
	String name;

	public Dog(int age, String name) {
		this.age = age;
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return "Dog [age=" + age + ", name=" + name + "]";
	}

//	@Override
//	public int compareTo(Object arg0) {
//		if (arg0 instanceof Dog) {
//			Dog d  = (Dog)arg0;
//			return this.name.compareTo(d.name);
//		}
//		throw new RuntimeException("Wrong type!");
//	}
	@Override
	public int compareTo(Object arg0) {
		if (arg0 instanceof Dog) {
			Dog d  = (Dog)arg0;
			int i = this.name.compareTo(d.name);
			if (i!=0) {
				return i;
			}else {
				if (d.age>this.age) {
					return -1;
				}
				return 1 ;
			}
			
		}
		throw new RuntimeException("Wrong type!");
	}

}
